﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using System.Data;
using System.IO;
using System.Drawing;
public partial class administrator_uc_admin_a_manager : WebPageSecurity
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }   
    protected void lbtAddNewItem_Click(object sender, EventArgs e)
    {
        try
        {
            if (int.Parse("0" + new CmsBLL().Manager_CheckUserName(txtUserName.Text.Trim())) > 0)
            {
                lblMessage.Text = "<b>" + txtUserName.Text + "</b> đã tồn tại!";
                return;
            }
            DateTime BirthDay = new DateTime();
            if(!string.IsNullOrEmpty(txtYear.Text))
                BirthDay = new DateTime(int.Parse("0" + txtYear.Text), int.Parse("0" + DropDownListMonth.SelectedValue), int.Parse("0" + DropDownListDay.SelectedValue));
            else BirthDay = DateTime.Now;
            string Password = SecurityServices.GetMD5(txtPassword.Text.Trim());
            new CmsBLL().Manager_InsertItem(Guid.NewGuid(), txtUserName.Text, Password, txtEmail.Text, txtFullName.Text, txtAddress.Text, BirthDay, int.Parse("0" + rdSex.SelectedValue), 0, DateTime.Now, DateTime.Now, int.Parse("0" + rdActive.SelectedValue), txtLockedReason.Text);
            lblMessage.Text = "Thêm mới thành công!";         
            ResetForm();
        }
        catch (Exception ex)
        {
            lblMessage.Text = "ERROR! " + ex.Message.ToString();
        }
    }
    private void ResetForm()
    {
        txtUserName.Text = "";
        txtPassword.Text = "";
        txtRePassword.Text = "";
        txtEmail.Text = "";
        txtFullName.Text = "";
        txtAddress.Text = "";
        DropDownListDay.SelectedValue="1";
        DropDownListMonth.SelectedValue = "1";
        txtYear.Text = "";
        rdSex.SelectedValue = "1";      
        rdActive.SelectedValue = "1";
        txtLockedReason.Text = "";
        txtUserName.Focus();
    }
}